//
//  YYETeacherCollectionViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2017/12/28.
//  Copyright © 2017年 胡波. All rights reserved.
//

#import "YYETeacherCollectionViewCell.h"

@interface YYETeacherCollectionViewCell ()

@property (nonatomic,strong) UIImageView *headerIV;
@property (nonatomic,strong) UIView *nameView;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *levelLabel;

@end

@implementation YYETeacherCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.headerIV = [[UIImageView alloc]init];
        self.headerIV.layer.cornerRadius = 33.5;
        self.headerIV.clipsToBounds = YES;
        [self.contentView addSubview:self.headerIV];
        
        self.nameView = [[UIView alloc]init];
        [self.contentView addSubview:self.nameView];
//        self.nameView.backgroundColor = [UIColor redColor];

        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        [self.nameView addSubview:self.nameLabel];
        
        self.levelLabel = [[UILabel alloc]init];
        self.levelLabel.textColor = [UIColor blackColor];
        self.levelLabel.font = [UIFont systemFontOfSize:11];
        self.levelLabel.textAlignment = NSTextAlignmentCenter;
        [self.nameView addSubview:self.levelLabel];
        
        self.headerIV.image = [UIImage imageNamed:@"teacherHolder"];
//        self.headerIV.backgroundColor = [UIColor redColor];
        self.nameLabel.text = @"陈晨";
        self.levelLabel.text = @"育英特级讲师";
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.headerIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(20);
        make.size.equalTo(CGSizeMake(67, 67));
        make.centerY.equalTo(self.contentView.centerY);
    }];
    
    [self.nameView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIV.right);
        make.right.top.bottom.equalTo(self.contentView);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameView.left).offset(10);
        make.centerX.equalTo(self.nameView.centerX);
        make.bottom.equalTo(self.nameView.centerY).offset(-2);
    }];
    
    [self.levelLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameView.left).offset(10);
        make.centerX.equalTo(self.nameView.centerX);
        make.top.equalTo(self.nameView.centerY).offset(3);
    }];
    
}

- (void)setModel:(YYEHomeCourseModel *)model {
    _model = model;
    
    [self.headerIV sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"headerHolder"]];
    self.nameLabel.text = model.name;
    self.levelLabel.text = model.role;
    
}

@end
